﻿
Imports System.Data.OleDb
Partial Public Class AddHotels
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkpetallowed.CheckedChanged

    End Sub

    Protected Sub btnAddhotel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddhotel.Click
        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("HotelConnectionString").ToString())
        conn.Open()
        Dim sqlString As String = "INSERT INTO hotel(HotelName,Description,PetsAllowed,Picture,Stars) VALUES (@HotelName,@Description,@PetsAllowed,@Picture,@Stars)"

        Dim fileLocationonServer = Request.MapPath("Images/" & picupload.FileName)
        picupload.SaveAs(fileLocationonServer)

        Dim relativePath As String = "Images/" & picupload.FileName

        Dim dbCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sqlString, conn)

        dbCmd.Parameters.AddWithValue("@HotelName", txtHotelname.Text)
        dbCmd.Parameters.AddWithValue("@Description", txtDesc.Text)
        dbCmd.Parameters.AddWithValue("@PetsAllowed", chkpetallowed.Checked)
        dbCmd.Parameters.AddWithValue("@Picture", relativePath)
        dbCmd.Parameters.AddWithValue("@Stars", txtstar.Text)


        dbCmd.ExecuteNonQuery()
        dbCmd.Dispose()
        conn.Close()
        conn.Dispose()
        Response.Redirect("Hotels.aspx")
    End Sub
End Class